package com.acme.bankapp.domain;
import java.io.Serializable;

import com.acme.bankapp.domain.Account;
import com.acme.bankapp.exception.*;
/**
 * Creating methods public boolean equals(Object obj) and public int hashCode() is requirement business logic and for further development of the project.
 * @author Troitskaya Aanastasia
 *
 */
public class SavingAccount extends Account {
	private double balance;
	SavingAccount(double startBalance) {
		super();
		this.balance = startBalance;
	}
	@Override
	void deposite(double delta) {
		this.balance += delta;
	}
	@Override
	void withdraw(double delta) throws NotEnoughFundsException {
		if (this.balance >= delta) {
			throw new NotEnoughFundsException();
		}
		else 
			if (this.balance >= delta) {
				this.balance -= delta;
			}
	}
	@Override
	public double getBalance() {
		return this.balance;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SavingAccount other = (SavingAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "SavingAccount [balance=" + balance + "]";
	}
	
}
